What is weighted graph?

A weighted graph is a type of graph in which each edge is assigned a numerical value, called a weight. These weights represent some kind of value associated with the connection between the vertices that the edge connects.

Weighted graphs are commonly used in various applications such as computer networking, transportation planning, and scheduling problems. The weights on the edges may represent distances, costs, time, or any other relevant metric that needs to be considered in the problem.

In a weighted graph, finding the shortest path between two vertices involves considering both the topology of the graph (the connections between vertices) and the weights assigned to the edges. This is typically done using algorithms such as Dijkstra's algorithm or the Bellman-Ford algorithm.

It is important to note that not all graphs are weighted; in an unweighted graph, all edges are considered to have the same weight or no weight at all. Weighted graphs provide a more flexible and powerful representation for many practical problems where the relationships between vertices have different values or costs associated with them.